//
//  JXBaseWKWebViewController.m
//  JXAddressApp
//
//  Created by zhhw_home on 2018/10/28.
//  Copyright © 2018年 zhhw_home. All rights reserved.
//

#import "JXBaseWKWebViewController.h"
#import "Masonry.h"
#import "JXAdviseViewController.h"
#import <QMUIKit/QMUICommonDefines.h>

@interface JXBaseWKWebViewController()

@property (nonatomic, strong) WKWebViewConfiguration *webViewConfiguration;

@end

@implementation JXBaseWKWebViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    if (@available(iOS 11.0, *)) {
        self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } 
    
    _webViewConfiguration = [[WKWebViewConfiguration alloc] init];
    _webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:self.webViewConfiguration];
    [self.view addSubview:_webView];
    
    CGFloat y = 64;
        
    if (IS_NOTCHED_SCREEN) {
        y = 88;
    }
    
    _webView.frame = CGRectMake(0, y, SCREEN_WIDTH, self.view.bounds.size.height-y);
    
    NSURLRequest *request = [NSURLRequest requestWithURL:self.webUrl];
    [self.webView loadRequest:request];
    
    if (_webVCTitle.length > 0) {
        self.title = _webVCTitle;
    }
    
    if (_flag == 1) {
        UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"留言" style:UIBarButtonItemStylePlain target:self action:@selector(advise:)];
        self.navigationItem.rightBarButtonItem = rightItem;
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)advise:(id)sender
{
    JXAdviseViewController *viewController = [[JXAdviseViewController alloc] init];
    [self.navigationController pushViewController:viewController animated:YES];
}

@end
